package trab4.transactions;

import trab4.time.* ;

abstract public class AbstractTransaction implements Comparable<AbstractTransaction> {

	protected final long tid ;
	protected final TimeStamp timeStamp ;
	
	protected AbstractTransaction( long tid, TimeStamp timeStamp ) {		
		this.tid = tid ;
		this.timeStamp = timeStamp ;
	}
	
	public long tid() {
		return tid ;
	}
	
	public int hashCode() {
		return new Long( tid ).hashCode() ;
	}
	
	public int compareTo( AbstractTransaction other) {
		return timeStamp.compareTo( other.timeStamp ) ;
	}

	public boolean equals( Object other ) {
		return other != null & equals( (AbstractTransaction) other ) ;
	}
	
	private boolean equals( AbstractTransaction other ) {
		return tid == other.tid;
	}
	
	public String toString() {
		return Long.toHexString(tid) + ":" + timeStamp.toString() ;
	}
}
